package com.ddpt.permission.export.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lh.center.common.export.ExportQueryService;
import com.lh.center.common.export.dto.permission.RoleDto;
import com.lh.center.common.export.vo.permission.RoleVo;
import com.lh.center.permission.api.entity.Role;
import com.lh.center.permission.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("roleExportService")
public class RoleExportServiceImpl implements ExportQueryService<RoleDto, RoleVo> {
    @Resource
    private RoleService roleService;

    @Override
    public List<RoleVo> query(RoleDto roleDto) {
        List<RoleVo> vos = new ArrayList<>();
        List<Role> list = roleService.list(Wrappers.lambdaQuery(Role.class)
                .like(null != roleDto.getName(), Role::getName, roleDto.getName()));
        list.stream().forEach(e -> {
            RoleVo vo = new RoleVo();
            BeanUtil.copyProperties(e, vo);
            vos.add(vo);
        });
        return vos;
    }
}
